package com.guoheng.hazard.manager.hikvision;

import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/**
 * 类功能描述:　海康摄像头业务调用层
 *
 * @author fbl
 * @date 2019-12-06 15:21
 */
@Service
public class CameraManager {

    static {
        ArtemisConfig.host = "192.168.10.10:443";// 代理API网关nginx服务器ip端口
        ArtemisConfig.appKey = "25625813";// 秘钥appkey
        ArtemisConfig.appSecret = "4Lda2ktPUCJYZPQkhZ3h";// 秘钥appSecret
    }

    /**
     * 能力开放平台的网站路径
     * TODO 路径不用修改，就是/artemis
     */
    private static final String ARTEMIS_PATH = "/artemis";

    /**
     * 获取监控点预览取流URL
     *
     * @param cameraIndexCode 监控点唯一标识
     * @return Result
     */
    public String getPreviewURLs(String cameraIndexCode) {
        final String getCamsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                // 根据现场环境部署确认是http还是https
                put("https://", getCamsApi);
            }
        };

        JSONObject jsonBody = new JSONObject();

        jsonBody.put("cameraIndexCode", cameraIndexCode);
        // hls:HLS协议（HLS协议只支持海康SDK协议、EHOME协议、GB28181协议、ONVIF协议接入的设备；只支持H264视频编码和AAC音频编码）
        jsonBody.put("protocol", "hls");
        String body = jsonBody.toJSONString();
        // post请求application/json类型参数
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, "application/json;charset=UTF-8", null);
        return result;
    }

}
